Welcome to Introduction to Web Frameworks. After watching this video, you will be able to: Explain the difference between Node.js
and Node.js-based web frameworks. Explain MVC and REST API architectural styles. And describe prominent features
of several Node web frameworks. Sometimes Node.js is incorrectly referred
to as a web framework. Node.js is not a framework but a
runtime environment that executes
JavaScript on a server. Runtime environments are the hardware and software that can execute programs
with a particular codebase. A framework, on the other hand, is like a skeleton
on which an application is built for a specific environment. The framework is the fundamental
structure that supports the application. So, in order to utilize Node.js, you need to use
a web framework that works in conjunction with it. A framework that works with Node.js is called
a node web framework or just a node framework. There are a number of different node frameworks.
And we will discuss a few later in this video. So, before discussing individual frameworks,
let’s first discuss two approaches to building back ends that web frameworks can employ: Model-View-Controller, better known as MVCs,
and Representational state transfer application
programming interfaces, or REST API for short. An MVC approach can be used simultaneously with
REST APIs. They are not mutually exclusive. MVC stands for “model view controller”.
MVC is an architectural pattern that divides an application into three
components: model, view, and controller. Let’s discuss what each of these components is. The model layer is responsible for managing the data of the application.
It interacts with the database and handles the data logic. The view is responsible for rendering the presentation of the
data that is passed to it by the model. And the controller regulates the flow of the
data. It is responsible for processing the data supplied to it by the user and sends that
data to the model for manipulation or storage. MVC frameworks are generally used to develop
applications that need a separation of data, called the model; the presentation
of the data called the view; and the module that manipulates
the data, which is the controller. Frameworks that lend themselves to
developing the back end with an MVC pattern include Koa, Django, Express, and NestJS. Now let’s discuss REST APIs. REST APIs allow multiple web
services to communicate with each other. RESTful APIs are subject
to certain constraints. The code on the client must be completely
independent of the server code. Client-side code can be updated without
interfering with the server code and vice versa. Secondly, RESTful APIs are also stateless. Stateless means the client does not
need to know the state of the server, nor does the server need to know the state of
the client for communication between the two. REST APIs communicate via operations on resources,
and they do not rely on a particular
implementation of the API. When a client requests resources using a REST
API using HTTP methods such as GET, POST, PATCH, or DELETE, the server responds with a representation
of the state of the resource to the client. The representation of the data transferred
between client and server is usually a JSON payload but can also be HTML,
XLT, Python, PHP, or plain text. So, now that we’ve discussed a couple of
ways to structure the back-end code, let’s dig deeper and discuss some of
the popular frameworks themselves. Express.js, aka Express, is one of the
most popular Node Web Frameworks. It is used for routing and middleware.
Its straightforward coding using JavaScript means there is a
fairly small learning curve. It is easy to implement an MVC architecture
pattern with Express. It provides debugging mechanisms to help
easily pinpoint the errors in the application. Express delivers high performance
because it handles multiple operation requests concurrently that are independent
of each other with asynchronous programming. It has many HTTP helpers that make
programs intelligible and reusable
for handling HTTP requests. It has great content negotiation that helps the
client and server to communicate by efficiently providing HTTP headers to URLs, fetching the
exact data needed for the requesting client. Koa is a relatively new web framework designed
by the same team who designed Express. It intends is designed to be smaller,
more expressive, and provide a more robust
foundation for web applications and APIs. Koa uses async functions in such a
way that callbacks are not necessary, and it increases the ability to handle errors. Koa is appropriate for applications
that are high-performing, demanding, complex, and developed by
large, experienced teams. Socket.io is an excellent choice for
developing apps where bidirectional data is exchanged between clients and
servers in real-time. You can develop applications that utilize
WebSocket rather than HTTP for communication. Its servers push data without the need
for that data to be called by the client. It is appropriate for applications such
as chat rooms, texting applications, video conferencing, and multiplayer games. Next, Hapi.js is a reliable open source node web
framework with lots of security built into it. There are many built-in plugins, so you
won’t need to use unofficial middleware. It is most known for developing proxy and API
servers, HTTP-proxy applications, REST APIs,
and other desktop applications. And finally, we have, the NestJS framework which is appropriate for
building dynamic, scalable enterprise
applications in conjunction with its flexibility due to its multitude of libraries.
It follows an MVC architecture. NestJS is built on top of Express, so they have similar
purposes and provide comparable functions. It is compatible with TypeScript, which
is a subset superset of JavaScript. It works in conjunction with the
front-end Angular framework. And Nest combines both object-oriented
and functional reactive programming, which potentially doubles productivity
and application performance. In this video, you learned that: Node.js is a runtime environment,
whereas node web frameworks use the
Node.js environment in order to run. The MVC architecture style divides a
back-end application into three parts: the model, the view, and the controller. REST API frameworks use HTTP methods
to communicate with each other And several popular node web frameworks include
Express, Koa, Hapi.js, and NestJS.